package xyz.zhouzhousag.server.controller;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;
import xyz.zhouzhousag.server.pojo.entity.BaseResponse;
import xyz.zhouzhousag.server.pojo.entity.NodeTab;
import xyz.zhouzhousag.server.service.NodeTabService;

import javax.annotation.Resource;

/**
 * 节点板块表(NodeTab)表控制层
 *
 * @author Yin.Liu8
 * @since 2021-09-26 16:21:12
 */
@RestController
@RequestMapping("nodeTab")
public class NodeTabController {
    /**
     * 服务对象
     */
    @Resource
    private NodeTabService nodeTabService;

    /**
     * 分页查询
     *
     * @param nodeTab     筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @GetMapping
    public BaseResponse<Page<NodeTab>> queryByPage(NodeTab nodeTab, PageRequest pageRequest) {
        return BaseResponse.success(this.nodeTabService.queryByPage(nodeTab, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public BaseResponse<NodeTab> queryById(@PathVariable("id") Integer id) {
        return BaseResponse.success(this.nodeTabService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param nodeTab 实体
     * @return 新增结果
     */
    @PostMapping
    public BaseResponse<NodeTab> add(NodeTab nodeTab) {
        return BaseResponse.success(this.nodeTabService.insert(nodeTab));
    }

    /**
     * 编辑数据
     *
     * @param nodeTab 实体
     * @return 编辑结果
     */
    @PutMapping
    public BaseResponse<NodeTab> edit(NodeTab nodeTab) {
        return BaseResponse.success(this.nodeTabService.update(nodeTab));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public BaseResponse<Boolean> deleteById(Integer id) {
        return BaseResponse.success(this.nodeTabService.deleteById(id));
    }

}

